package com.coscoshipping.rams.demo.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.coscoshipping.rams.demo.entity.BlockAnalysis;
import com.coscoshipping.rams.demo.mapper.BlockAnalysisMapper;
import com.coscoshipping.rams.demo.service.IBlockAnalysisService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coscoshipping.rams.demo.service.IBlockHeaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhaoyin.yang
 * @since 2025-01-15
 */
@Service
public class BlockAnalysisServiceImpl extends ServiceImpl<BlockAnalysisMapper, BlockAnalysis> implements IBlockAnalysisService {

    @Autowired
    private IBlockHeaderService blockHeaderService;


    /**
     * @description 将block信息插入block分析表
     * @return: void
     * @author 杨召银
     * @date 2025/1/15 16:13
     */
    @Override
    @DS("slave_1")
    public void addBlockAnalysis(){
        blockHeaderService.getBlockHeaderList("").forEach(blockHeader -> {
            // 如果数据库没有该条数据，则插入
            BlockAnalysis analysis=this.lambdaQuery().eq(BlockAnalysis::getBlockcode,blockHeader.getBlockcode()).one();
            if(ObjectUtil.isEmpty(analysis)){
                this.save(blockHeader);
            }
        });
    }



}
